package day15.线程的练习;

public class ThreadStateDemo01 {
    public static void main(String[] args) throws InterruptedException {
        Object obj = new Object();
        Thread thread = new Thread(() -> {
            System.out.println(("2.执行thread.start()之后，线程的状态：" + Thread.currentThread().getState()));

            synchronized (obj) {
                try {
                    Thread.sleep(100);
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(("4.被object.notify()方法唤醒之后，线程的状态：" + Thread.currentThread().getState()));
            }
        });
        System.out.println("1.通过new初始化一个线程，但是还没有start()之前，线程的状态："+thread.getState());
        thread.start();
        Thread.sleep(150);
        System.out.println("3.执行object.wait()时，线程的状态："+thread.getState());
        new Thread(()->{
            synchronized (obj){
                obj.notify();
            }
        }).start();
        Thread.sleep(10);
        System.out.println(("5.线程执行完毕之后，线程的状态："+thread.getState()+"\n"));

    }
}